/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View;

import Model.InitialData;
import javax.swing.JOptionPane;

/**
 *
 * @author William
 */
public class Application extends javax.swing.JFrame {

    public static InitialData initialData = new InitialData();

    /**
     * Creates new form Application
     */
    public Application() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        datosInicialesMenuItem = new javax.swing.JMenuItem();
        algCohonMenuItem = new javax.swing.JMenuItem();
        algGoicocheaMenuItem = new javax.swing.JMenuItem();
        salirMenuItem = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Metodos de las restricciones.");
        setBackground(new java.awt.Color(255, 255, 255));
        setMaximumSize(new java.awt.Dimension(1024, 768));
        setMinimumSize(new java.awt.Dimension(600, 400));
        setPreferredSize(new java.awt.Dimension(600, 400));

        mainPanel.setBackground(new java.awt.Color(255, 255, 255));
        mainPanel.setPreferredSize(new java.awt.Dimension(600, 400));
        mainPanel.setLayout(new java.awt.BorderLayout());

        jMenuBar1.setBackground(new java.awt.Color(255, 255, 255));

        jMenu1.setBackground(new java.awt.Color(255, 255, 255));
        jMenu1.setText("Menú");

        datosInicialesMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.ALT_MASK));
        datosInicialesMenuItem.setBackground(new java.awt.Color(255, 255, 255));
        datosInicialesMenuItem.setText("Ingresar datos iniciales.");
        datosInicialesMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                datosInicialesMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(datosInicialesMenuItem);

        algCohonMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK));
        algCohonMenuItem.setBackground(new java.awt.Color(255, 255, 255));
        algCohonMenuItem.setText("Algoritmo de Cohon.");
        algCohonMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                algCohonMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(algCohonMenuItem);

        algGoicocheaMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_G, java.awt.event.InputEvent.ALT_MASK));
        algGoicocheaMenuItem.setText("Algoritmo de Goicochea.");
        algGoicocheaMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                algGoicocheaMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(algGoicocheaMenuItem);

        salirMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.ALT_MASK));
        salirMenuItem.setText("Salir.");
        salirMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salirMenuItemActionPerformed(evt);
            }
        });
        jMenu1.add(salirMenuItem);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Ayuda");
        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void algCohonMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_algCohonMenuItemActionPerformed
        if (!initialData.isSaved()) {
            JOptionPane.showMessageDialog(this, "Ingrese los datos primero.", "Información.", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        CohonPanel cp = new CohonPanel();
        mainPanel.setVisible(false);
        mainPanel.removeAll();
        mainPanel.add(cp);
        mainPanel.setVisible(true);
    }//GEN-LAST:event_algCohonMenuItemActionPerformed

    private void salirMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salirMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_salirMenuItemActionPerformed

    private void datosInicialesMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_datosInicialesMenuItemActionPerformed
        InitialDataPanel idp = new InitialDataPanel();
        mainPanel.setVisible(false);
        mainPanel.removeAll();
        mainPanel.add(idp);
        mainPanel.setVisible(true);
    }//GEN-LAST:event_datosInicialesMenuItemActionPerformed

    private void algGoicocheaMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_algGoicocheaMenuItemActionPerformed
        if (!initialData.isSaved()) {
            JOptionPane.showMessageDialog(this, "Ingrese los datos primero.", "Información.", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        GoicocheaPanel gp = new GoicocheaPanel();
        mainPanel.setVisible(false);
        mainPanel.removeAll();
        mainPanel.add(gp);
        mainPanel.setVisible(true);
    }//GEN-LAST:event_algGoicocheaMenuItemActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Application.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Application.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Application.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Application.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        Application application = new Application();
        application.setLocationRelativeTo(null);
        application.setVisible(true);
        initialData.setNumberObjetives(2);
        initialData.setNumberVariables(2);
        initialData.setNumberRestrictions(2);
        double ob[][] = {{10.0,3.0}, {0.8,1.3}};
        double res[][] = {{1.0,1.0}, {2.5,1.0}};
        double c[]={130,250};
        initialData.setLdData(c);
        initialData.setObjectiveData(ob);
        initialData.setRestrictionData(res);
        initialData.setSaved(true);

        //ejemplos
//        GoicocheaProblem G = new GoicocheaProblem(2);
//
//        double c[] = new double[2];
//        double d[] = new double[2];
//        c[0] = 10;
//        c[1] = 3;
//        d[0] = 0.8;
//        d[1] = 1.3;
//        
//         double e[][]= new double [2][2];
//        e[0][0] = 10;
//        e[0][1] = 3;
//        e[1][0] = 0.8;
//        e[1][1] = 1.3;
//        
//        G.setObjectives(e);
//        double A[][] = new double[2][2];
//        A[0][0]= 1;
//        A[0][1]= 1;
//        A[1][0]= 2.5;
//        A[1][1]= 1;
//        double B[] = new double [2];
//        B[0]= 130;
//        B[1]= 250;
//        
//        
//        
//        Simplex prueba = new Simplex(A,B,c);
//        Simplex prueba2 = new Simplex(A,B,d);
//        
//        double result[][] = new double[2][2];
//        
//        result[0] = prueba.primal();
//        result[1] = prueba2.primal();
//        for(int i =0; i<2; i++){
//            for(int j=0;j<2; j++){
//            System.out.println(result[i][j]);
//            }
//        }
//        
//        G.setResult(result);
//         
//        //Prueba del Zmaxim (paso 4) con G, G contiene G.setObjectives(e) y G.setResult(result)
//        GoicocheaController.Zmaxim(G);
//        
//        double zmax[] = G.getZMax();
//        
//        System.out.println(zmax[0] + " " + zmax[1]);
//        double a1 [][] = new double[3][3];
//        a1 [0][0]=1;
//        a1 [0][1]=1;
//        a1 [0][2]=0;
//        a1 [1][0]=2.5;
//        a1 [1][1]=1;
//        a1 [1][2]=0;
//        a1 [2][0]=-10;
//        a1 [2][1]=-3;
//        a1 [2][2]=0;
//        double b1 []= new double[3];
//        b1[0]=130;
//        b1[1]=250;
//        b1[2]=-817;
//        double c1[] = new double[2];
//        c1[0]=0.8/89;
//        c1[1]=1.3/89;
//        //c1[2]=80/89;
//        Simplex s = new Simplex(a1, b1, c1);
//        double t [] = s.primal();
//        for (int i =0 ; i< t.length;i++){
//            System.out.print(t[i] + " ");
//        }


    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem algCohonMenuItem;
    private javax.swing.JMenuItem algGoicocheaMenuItem;
    private javax.swing.JMenuItem datosInicialesMenuItem;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuItem salirMenuItem;
    // End of variables declaration//GEN-END:variables
}
